本文介绍如何在AWS EC2一个实例下安装多个wordpress。我之前已在/var/www/安装了一个WordPress,安装过程见博文《已将博客迁移到亚马逊云:简要笔记》。在此基础上再安装一个WordPress。

步骤1:下载wordpress

SSH登录到AWS EC2,进入到/var/www/目录,用wget工具下载WordPress,相关命令如下:

wget https://cn.wordpress.org/wordpress-4.2.2-zh_CN.tar.gz

tar -xvf wordpress-4.2.2-zh_CN.tar.gz
mv wordpress zhilitea.com
sudo chmod -R 755 zhilitea.com

步骤2:Web服务器配置文件

/etc/apache2/sites-available/目录下创建配置文件zhilitea.com.conf,对着000-default.conf修改,最后内容如下(以zhilitea.com为例):

<VirtualHost *:80>
    ServerAdmin admin@zhilitea.com
    ServerName zhilitea.com
    ServerAlias www.zhilitea.com
    DocumentRoot /var/www/zhilitea.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

启用设置文件

sudo a2ensite zhilitea.com.conf
sudo service apache2 restart

步骤3:修改hosts文件

打开/etc/hosts文件,在文件末尾添加如下内容:

# added by sparkandshine
# xx.xx.xx.xx为AWS EC2 Elastic IP
xx.xx.xx.xx zhilitea.com

步骤4:修改DNS解析

将zhilitea.com的A记录@解析到xx.xx.xx.xx(为AWS EC2 Elastic IP)。

@ --> xx.xx.xx.xx  # xx.xx.xx.xx为AWS EC2 Elastic IP

好了,大功告成。现在可以同时访问sparkandshine.netzhilitea.com

问题及解决

访问主机zhilitea.com一切正常,但访问文章时,比如http://zhilitea.com/just-for-test/,就提示如下问题:

Not Found

The requested URL /just-for-test/ was not found on this server.

Apache/2.4.7 (Ubuntu) Server at zhilitea.com Port 80

原来是这个站点目录下缺少.htaccess文件,详情见博文《解决"The requested URL was not found on this server"》。

参考资料:

[1] Blog: How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS

[2] Blog: MULTIPLE WEBSITES ON AMAZON EC2 LINUX WITH VIRTUAL HOSTS

[3] Blog: Host Multiple Sites on a Single Amazon EC2 Instance

本文系Spark & Shine原创,转载需注明出处本文最近一次修改时间 2022-04-17 11:29

results matching ""

    No results matching ""